package tarantula.instrumenter;

import java.io.File;
import java.util.Properties;

import tarantula.util.FileUtils;
import tarantula.util.Globals;
import junit.framework.TestCase;

public class TestUnifiedInstrumentMain extends TestCase {
	
	private static String instrumentbasedir = null;
	
	static {
		PropertyReader.reloadProperty(PropertyReader.default_file);
		instrumentbasedir = PropertyReader.getProperty("instrumentbasedir");
	}
	
	public void testInstrumentApacheCommons() {
		
		String folder = PropertyReader.getProperty("collections-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder + Globals.fileSep;
		
		String inputDir = path + PropertyReader.getProperty("collections-original");
		String outputDir = path + PropertyReader.getProperty("collections-instrumented-dirname");
		String junitInputDir = path + PropertyReader.getProperty("collections-tests-original");
		String junitOutputDir =path + PropertyReader.getProperty("collections-tests-instrumented-dirname");
		String includePkg = "org.apache.";
		String extraCp = "";
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
		
	}
	
	public void testInstrumentApacheMath() {
		String folder = PropertyReader.getProperty("math-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder  + Globals.fileSep;
		
		String inputDir = path + PropertyReader.getProperty("math-original");
		String outputDir = path + PropertyReader.getProperty("math-instrumented-dirname");
		String junitInputDir = path + PropertyReader.getProperty("math-tests-original");
		String junitOutputDir =path + PropertyReader.getProperty("math-tests-instrumented-dirname");
		String includePkg = "org.apache.";
		String extraCp = "";
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
	}
	
	public void testInstrumentPrimitive() {
		String folder = PropertyReader.getProperty("primitive-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder  + Globals.fileSep;
		
		String inputDir =  path + PropertyReader.getProperty("primitive-original");
		String outputDir = path + PropertyReader.getProperty("primitive-instrumented-dirname");
		String junitInputDir = path + PropertyReader.getProperty("primitive-tests-original");
		String junitOutputDir =path + PropertyReader.getProperty("primitive-tests-instrumented-dirname");
		String includePkg = "org.apache.";
		String extraCp = "";
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
	}
	
	public void testInstrumentBeanutil() {
		String folder = PropertyReader.getProperty("beanutils-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder  + Globals.fileSep;
		
		String inputDir = path + PropertyReader.getProperty("beanutils-original");
		String outputDir =  path + PropertyReader.getProperty("beanutils-instrumented-dirname");
		String junitInputDir =  path + PropertyReader.getProperty("beanutils-tests-original");
		String junitOutputDir =path + PropertyReader.getProperty("beanutils-tests-instrumented-dirname");
		String includePkg = "org.apache.";
		String extraCp = "";
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
	}
	
	public void testInstrumentJDom() {
		String folder = PropertyReader.getProperty("jdom-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder  + Globals.fileSep;
		
		String inputDir = path + PropertyReader.getProperty("jdom-original");
		String outputDir = path + PropertyReader.getProperty("jdom-instrumented-dirname");
		String junitInputDir = path + PropertyReader.getProperty("jdom-tests-original");
		String junitOutputDir = path + PropertyReader.getProperty("jdom-tests-instrumented-dirname");
		
		String includePkg = "org.jdom.";
		String extraCp = PropertyReader.getProperty("jaxenjarfile"); 
			//"G:/72_Simplify/workspace_simplify/TestsForJDom/lib/jaxen-1.1.3.jar";
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
	}
	
	public void testInstrumentTimeAndMoney() {
		String folder = PropertyReader.getProperty("timeandmoney-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder  + Globals.fileSep;
		
		String inputDir =  path + PropertyReader.getProperty("timeandmoney-original");
		String outputDir = path + PropertyReader.getProperty("timeandmoney-instrumented-dirname");
		String junitInputDir =  path + PropertyReader.getProperty("timeandmoney-tests-original");
		String junitOutputDir = path + PropertyReader.getProperty("timeandmoney-tests-instrumented-dirname");
		String includePkg = "com.domainlanguage.";
		String extraCp = PropertyReader.getProperty("junitfile");
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
	}
	
	public void testInstrumentJDKUtils() {
		String folder = PropertyReader.getProperty("jdkutil-dirname");
		String path = instrumentbasedir + Globals.fileSep + folder  + Globals.fileSep;
		
		String inputDir = path + PropertyReader.getProperty("jdkutil-original");
		String outputDir = path + PropertyReader.getProperty("jdkutil-instrumented-dirname");
		String junitInputDir = path + PropertyReader.getProperty("jdkutil-tests-original");
		String junitOutputDir =path + PropertyReader.getProperty("jdkutil-tests-instrumented-dirname");
		String includePkg = "java.util.";
		String extraCp = "";
		Main.main(this.createArgs(inputDir, outputDir, junitInputDir, junitOutputDir, includePkg, extraCp));
	}
	
	private String[] createArgs(String inputdir, String outputdir,
			String junitInputDir, String junitOutputDir, String includePackage, String extraClasspath) {
		FileUtils.checkDirExist(inputdir);
		FileUtils.checkDirExist(junitInputDir);
		FileUtils.createDir(outputdir);
		FileUtils.createDir(junitOutputDir);
		return new String[] {
				"--input_dir=" + inputdir,
				"--output_dir=" + outputdir,
				"--junit_input_dir=" + junitInputDir,
				"--junit_output_dir=" + junitOutputDir,
				//"--output_format=J", //comment out this line will make the test pass
				"--additional_classpath=" + inputdir + File.pathSeparator + extraClasspath,
				"--include_subject_package=" + includePackage
		};
	}
	
	
}